import json

import requests


class RequestsUtil:
    session = requests.Session()

    def send_request(self,method, url, data, **kwargs):
        method = str(method).lower()  # 转化请求方式为小写
        rep = None
        if method == 'get':
            rep = RequestsUtil.session.request(method=method, url=url, params=data, **kwargs)
        else:
            data = json.dumps(data)  # 不管他传输过来的是什么格式都转化为字符串进行传参
            rep = RequestsUtil.session.request(method=method, url=url, data=data, **kwargs)  # json和data都可以传参，使用data全部包括
        return rep.text
